<template>
  <div class="date-range">
    <el-date-picker
      :value="value"
      type="daterange"
      placeholder="选择日期"
      :clearable="false"
      range-separator="~"
      :picker-options="pickerOptions"
      value-format="yyyy-MM-dd"
      v-bind="$attrs"
      v-on="$listeners"
    >
    </el-date-picker>
  </div>
</template>

<script type="text/javascript">
export default {
  name: 'DateRange',
  components: {},
  props: {
    value: {
      type: Array,
      required: true
    }
  },
  data () {
    return {
      pickerOptions: {
        shortcuts: [
          {
            text: '过去1周',
            onClick (picker) {
              const end = new Date()
              const start = new Date()
              start.setDate(start.getDate() - 6)
              picker.$emit('pick', [start, end])
            }
          },
          {
            text: '过去2周',
            onClick (picker) {
              const end = new Date()
              const start = new Date()
              start.setDate(start.getDate() - 13)
              picker.$emit('pick', [start, end])
            }
          },
          {
            text: '过去1个月',
            onClick (picker) {
              const end = new Date()
              const start = new Date()
              start.setDate(start.getDate() - 29)
              picker.$emit('pick', [start, end])
            }
          },
          {
            text: '过去3个月',
            onClick (picker) {
              const end = new Date()
              const start = new Date()
              start.setDate(start.getDate() - 89)
              picker.$emit('pick', [start, end])
            }
          }
        ],
        disabledDate (time) {
          return time.getTime() > new Date().setHours(0, 0, 0, 0)
        }
      }
    }
  },
  methods: {}
}
</script>
